package com.ruoyi.mall.app.service.impl;


import com.ruoyi.mall.app.service.DtsCateDetailService;
import com.ruoyi.mall.common.domain.DtsCategory;
import com.ruoyi.mall.common.mapper.DtsCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;


@Service
public class DtsCateDetailServiceImpl implements DtsCateDetailService {

    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void init()
    {
        List<DtsCategory>  list = dtsCategoryMapper.getCateDetail();
        redisTemplate.opsForValue().set("cateList", list);
    }

    @Override
    public List<DtsCategory> getCateDetail() {
        List<DtsCategory> list = (List<DtsCategory>) redisTemplate.opsForValue().get("cateList");
        if (list != null) {
            return list;
        }
        List<DtsCategory> tmp = dtsCategoryMapper.getCateDetail();
        if (tmp != null) {
            redisTemplate.opsForValue().set("cateList", tmp);
        }
        return dtsCategoryMapper.getCateDetail();
    }

    @Override
    public List<DtsCategory> getCateDetail2(Long id) {
        return dtsCategoryMapper.getCateDetail2(id);
    }
}
